/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service;

import beans.ListPlacas;
import dao.Conexion;
import dao.VehiculoDAO;
import java.sql.SQLException;

/**
 *
 * @author Ahmed
 */
public class VehiculoService {
    private static VehiculoDAO vehiculoDAO = new VehiculoDAO();
    private static Conexion conexion = new Conexion();
    
    public ListPlacas listarPlacas() {
        
        ListPlacas lPlacas = new ListPlacas();
        
        try{
            conexion.abrirConexion();
            vehiculoDAO.setConexion(conexion);
            lPlacas=vehiculoDAO.listarPlacas();
        }
        catch(SQLException | InstantiationException | IllegalAccessException | ClassNotFoundException e){
            lPlacas.me = "Error en BD al Listar Roles";
        }
        finally{
            try{
                conexion.cerrarConexion();
            }catch(SQLException e){
            }
        }
        return lPlacas;
        
    }

    public void ingresarHoraExtra() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
        try{
            conexion.abrirConexion();
            vehiculoDAO.setConexion(conexion);
            conexion.setAutoCommit(false);
            vehiculoDAO.ingresarHoraExtra();
            conexion.commit();
            
        }
        catch (SQLException | InstantiationException | IllegalAccessException | ClassNotFoundException e){
            conexion.rollback();
            throw e;
        }
        finally{
            try{
                conexion.cerrarConexion();
            }catch(SQLException e){
                throw e;
            }
        }        
    }

    public void ingresarIncidencias() throws SQLException, InstantiationException, IllegalAccessException, ClassNotFoundException {
        try{
            conexion.abrirConexion();
            vehiculoDAO.setConexion(conexion);
            conexion.setAutoCommit(false);
            vehiculoDAO.ingresarIncidencias();
            conexion.commit();
        }
        catch (SQLException | InstantiationException | IllegalAccessException | ClassNotFoundException e){
            conexion.rollback();
            throw e;
        }
        finally{
            try{
                conexion.cerrarConexion();
            }catch(SQLException e){
                throw e;
            }
        }
        
    }

    public ListPlacas listarPlacas(String tipo) {
        ListPlacas lPlacas = new ListPlacas();
        
        try{
            conexion.abrirConexion();
            vehiculoDAO.setConexion(conexion);
            lPlacas=vehiculoDAO.listarPlacas(tipo);
        }
        catch(SQLException | InstantiationException | IllegalAccessException | ClassNotFoundException e){
            lPlacas.me = "Error en BD al Listar Roles";
        }
        finally{
            try{
                conexion.cerrarConexion();
            }catch(SQLException e){
            }
        }
        return lPlacas;
    }
}
